<template>
  <!-- 车辆 -->
  <el-dialog
    title="选择车辆"
    :visible="value"
    append-to-body
    @open="handleOpen"
    @close="handleClose"
  >
    <el-form ref="carParam" :model="carParams">
      <el-row class="search">
        <el-col :span="8">
          <el-form-item label="车牌号" prop="carNo"  label-width="68px">
            <el-input v-model="carParams.carNo" maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item   label-width="12px">
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="carRhandleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="carResetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="carBasicList" height="500px" border>
      <el-table-column label="车牌号" align="center" min-width="120" show-overflow-tooltip prop="carNo" />
      <el-table-column label="车架号" align="center" min-width="120" show-overflow-tooltip prop="vinNo" />
      <el-table-column label="车辆信息" align="center" min-width="150" show-overflow-tooltip prop="carInfo" />
      <el-table-column
        label="操作"
        align="center"
        width = "120"
        fixed="left"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="selectCar(scope.row)"
            >选择</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="totalcarBasic"
      :page.sync="carParams.pageNum"
      :limit.sync="carParams.pageSize"
      @pagination="getList"
       :pager-count="5"
    />
  </el-dialog>
</template>

<script>
import { carBasicPermissionList } from '@/api/maintenance/insurance'

export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    statusArr: {
      type: String,
      default: null,
    },
    monitoring: {
      type: Number,
      default: null,
    },
    repairStatus: {
      type: String,
      default: null,
    },
    carNo: {
      type: String,
      default: null,
    },
    carStatus: {
      type: Number,
      default: null,
    },
    deptId:{
      type: Number,
      default: null,
    }
  },
  data() {
    return {
      loading: true,
      carBasicList: [],
      totalcarBasic: 0,
      carParams: {
        carNo: null,
        pageNum: 1,
        pageSize: 10,
        statusArr: this.statusArr,
        deptId: this.deptId,
        carStatus: this.carStatus,
        monitoring: this.monitoring,
        repairStatus: this.repairStatus,
      },
    }
  },
  created() {
    this.carResetQuery();
  },
  methods: {
    handleOpen() {
      this.getList()
    },
    handleClose() {
      this.$emit('input', false)
    },
    getList() {
      this.loading = true
      carBasicPermissionList(this.carParams).then((response) => {
        this.carBasicList = response.rows
        this.totalcarBasic = response.total
        this.loading = false
      })
    },
    carRhandleQuery() {
      this.carParams.pageNum = 1
      this.carParams.statusArr = this.statusArr
      this.getList(this.carParams)
    },
    carResetQuery() {
      this.carParams.statusArr = this.statusArr
      this.resetForm('carParam')
      this.carRhandleQuery()
    },
    selectCar(data) {
      this.$emit('success', data)
    },
  },
}
</script>

<style>
</style>
